<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
  <div class="body-content">
    <form method="post"  class="form-x" action="/workview/updataSupervice1" >
	
	<div class="student-list" id="student-list" name="student-list">
	
		
	</div>



      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="button" id="button bg-main icon-check-square-o" onclick="check11()" > 提交</button>
        </div>
      </div>
	  
    </form>
  </div>
</div>

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
    $(function() {
        var course_id = localStorage.getItem("courseno");
        $.ajax({
            dataType:"json",
            type: "POST",
            url: "/workview/course_libraryIdlist",
            data: ({
                course_id: course_id
            }),
            success: function (data) {
                console.log(data);
                if (data.status == 401) {
                    alert("熔断开启，系统异常");
                    window.location.href = "login.html";
                    return;
                }
                if (data.status == 200) {
                    var lists = data.data;
                    console.log(data);
                    for (var i = 0; i < lists.length; i++) {
                        var html = "";
                        html += `<div class="form-group">
                                    <div class="label">
                                        <label>请输入课程id：</label>
                                    </div>
                                    <div class="field">
                                        <input type="test" class="input w50" value="${lists[i].course_id}" name="course_id" id="course_id" data-validate="required:请输入课程id" />
                                        <span style="margin-left: 10px; color: red;">*</span>
                                        <div class="tips"> </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="label">
                                        <label>课程名称：</label>
                                    </div>
                                    <div class="field">
                                        <input type="test" class="input w50" value="${lists[i].course_name}" name="course_name" id="course_name" data-validate="required:请输入课程名称" />
                                        <span style="margin-left: 10px; color: red;">*</span>
                                        <div class="tips"> </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="label">
                                      <label>选择学院：</label>
                                    </div>

                                    <div class="field">
                                      <select name="college_name" id="college_name"  class="input w50">
                                        <option selected="selected">${lists[i].college_name}</option>
                                         <option value="软件学院">软件学院</option>
                                         <option value="人文学院">人文学院</option>
                                      </select>
                                       <span style="margin-left: 10px; color: red;">*</span>
                                      <div class="tips"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                  <div class="label">
                                    <label>成绩规则：</label>
                                  </div>
                                  <div class="field">
                                     <select name="performance_rule_id" id="performance_rule_id" class="input w50">
                                          <option selected="selected">${lists[i].performance_rule_id}</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                      </select>
                                    <span style="margin-left: 10px; color: red;">*</span>
                                    <div class="tips"> </div>
                                  </div>
                                </div>

                              <div class="form-group">
                                <div class="label">
                                  <label>课时：</label>
                                </div>
                                <div class="field">
                                  <input type="text" class="input w50" value="${lists[i].class_hour}" name="class_hour" id="class_hour" data-validate="required:请输入课时" />
                                  <span style="margin-left: 10px; color: red;">*</span>
                                  <div class="tips"> </div>
                                </div>
                              </div>


                              <div class="form-group">
                                <div class="label">
                                  <label>学分：</label>
                                </div>
                                <div class="field">
                                  <input type="text" class="input w50"  value="${lists[i].credit}" name="credit" id="credit" data-validate="required:请输入学分"/>
                                  <div class="tips"> </div>
                                </div>
                              </div>



                              <div class="form-group">
                                <div class="label">
                                  <label>课组名字：</label>
                                </div>
                                <div class="field">
                                  <input type="text" class="input w50"  value="${lists[i].course_group_name}" name="course_group_name" id="course_group_name" data-validate="required:请输入课组名字" />
                                  <span style="margin-left: 10px; color: red;">*</span>
                                  <div class="tips"> </div>
                                </div>
                              </div>

                                <div class="form-group">
                                  <div class="label">
                                    <label>简介：</label>
                                  </div>
                                  <div class="field">
                                    <input type="text" class="input w50" value="${lists[i].introduction}" name="introduction" id="introduction" />
                                    <div class="tips"> </div>
                                  </div>
                                </div>

                             <div class="form-group">
                               <div class="label">
                                 <label>备注：</label>
                               </div>
                               <div class="field">
                                 <input type="text" class="input w50" value="${lists[i].remark}" name="remark" id="remark"  />
                                 <div class="tips"> </div>
                               </div>
                             </div>`

                        $('.student-list').html(html);
                    }

                    return;
                }
                if (data.status == 500) {
                    alert("添加失败");
                    window.location.href = "adminlist.html";
                    return;
                }
                if (data.status == null) {
                    alert("添加异常");
                    window.location.href = "adminlist.html";
                    return;
                }
            },
            error: function (XMLHttpRequest, textStatus) {
                if (textStatus === 'timeout') {
                    alert('請求超時');
                    setTimeout(function () {
                        alert('重新请求');
                    }, 2000);
                }
                // window.location.href="login.html";
                alert("系统异常ajax失败");
            }

        })
    })
    function check11() {
        var course_id = document.getElementById("course_id").value;
        var course_name = document.getElementById("course_name").value;
        var college_name = document.getElementById("college_name").value;
        var performance_rule_id = document.getElementById("performance_rule_id").value;
        var class_hour = document.getElementById("class_hour").value;
        var credit = document.getElementById("credit").value;
        var course_group_name = document.getElementById("course_group_name").value;
        var introduction = document.getElementById("introduction").value;
        var remark = document.getElementById("remark").value;

        if(course_id == null || course_id == ""){
            alert("工号不能为空");
            return;
        }
        if(course_name == null || course_name == ""){
            alert("课程名字不能为空");
            return;
        }
        if(college_name == null || college_name == ""){
            alert("学院名字不能为null");
            return;
        }
        if(performance_rule_id == null || performance_rule_id == ""){
            alert("规则不能为null");
            return;
        }
        if(class_hour != class_hour ){
            alert("学时不能为null");
            return;
        }
        if(credit == null || credit == ""){
            alert("学分不能为null");
            return;
        }
        if(course_group_name == null || course_group_name == ""){
            alert("课程组名称不能为null ");
            return;
        }

        $.ajax({
            type:"POST",
            dataType:"json",
            url:"/workview/updataCourse_library",
            data:({
                course_id: course_id,
                course_name: course_name,
                college_name: college_name,
                performance_rule_id: performance_rule_id,
                class_hour: class_hour,
                credit: credit,
                course_group_name: course_group_name,
                introduction: introduction,
                remark: remark
            }),
            success: function (data) {
               // console.log(data);
                if (data.status == 401) {
                    alert("熔断开启，系统异常");
                    window.location.href = "login.html";
                    return;
                }
                if (data.status == 200) {
                    alert("修改成功")
                    window.location.href = "adminlist.html";
                    return;
                }
                if (data.status == 500) {
                    alert("修改失败");
                    window.location.href = "adminlist.html";
                    return;
                }
                if (data.status == null) {
                    alert("异常");
                    window.location.href = "adminlist.html";
                    return;
                }
            },
            error: function (XMLHttpRequest, textStatus) {
                if (textStatus === 'timeout') {
                    alert('請求超時');
                    setTimeout(function () {
                        alert('重新请求');
                    }, 2000);
                }
                window.location.href = "adminlist.html";
            }

        });
    }






</script>
</body>
</html>